using System;
using System.Threading.Tasks;
using Blog.BLL;
using Blog.DAL;
using Blog.Models;
using Microsoft.AspNetCore.Mvc;

namespace Blog.Controllers
{
    public class LoginController : BaseController
    {
        IAccountBLL bll;
        public LoginController(IAccountBLL accountBLL)
        {
            bll=accountBLL;
        }
        
        public IActionResult Login()
        {
            return View();
        }
        [HttpPost]
        public IActionResult LoginPost([Bind("UserName,PassWord,HeadPortraitsUrl")] Account accont)
        {

            return Json("");
        }
        public IActionResult Logup()
        {

            return View();
        }
        [HttpPost]
        public async Task<IActionResult> LogupPost([Bind("UserName,PassWord,HeadPortraitsUrl")] Account accont)
        {
            if (!ModelState.IsValid)
            {
                return Json(new { Res = 0, msg = "验证不通过" });
            }
            if(string.IsNullOrEmpty(accont.PassWord)||string.IsNullOrEmpty(accont.UserName))return Json(new { Res = 0, msg = "用户名或密码错误" });
            var res=await bll.InsertAsync(accont);
            return Json(new { Res = res, msg = res>0?"添加成功":"添加失败" });
        }

    }
}